﻿using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Security.Principal;
using System.Web;

namespace Lead2012.Business
{
    public partial class UserRepository
    {
        Lead2012Entities entities = new Lead2012Entities();

        public List<User> GetAll()
        {
            return (from c in entities.UserSet select c).ToList();
        }

        public User GetSingle(int id)
        {
            return (from c in entities.UserSet where c.ID == id select c).FirstOrDefault();
        }

        public User GetSingle(string username)
        {
            return (from c in entities.UserSet where c.Username == username select c).FirstOrDefault();
        }

        public void Delete(int id)
        {
            try
            {
                var _object = (from _list in entities.UserSet where _list.ID == id select _list).First();
                entities.DeleteObject(_object);
                entities.SaveChanges();
            }
            catch
            {
            }
        }

        public void Save(User _object)
        {
            try
            {
                _object.LastModified = System.DateTime.Now;
                entities.SaveChanges();
            }
            catch
            {
            }
        }

        public void SaveIsLockedOut(User _object)
        {
            try
            {
                _object.LastLockedOutDate = DateTime.Now;
                entities.SaveChanges();
            }
            catch
            {
            }
        }
    }
}